package study.kit.el.zh.table;

import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;

import java.util.List;
import java.util.Map;

public class TableV2Util {
    //
    private static Map<String, String> NAME_TO_FIELD = MapUtil.<String, String>builder()
            .put("季度", "quarter")
            .put("课次", "lessonNo")
            .put("课程名称", "lessonName")
            .put("知识点", "knoPoint")
            .put("切片链接", "cutLinks")
            .put("难度", "difficulty")
//            .put("首三推荐", "f3")
//            .put("重要性（文本说明）", "importance")
//            .put("题库知识图谱", "knoAtlas")
//            .put("切片id", "cutLinkIds")
//            .put("知识图谱id", "knoAtlasIds")
            .build();

    /**
     * 构造头
     */
    public static String getFieldName(Integer colNum, Map<Integer, String> colNum2NameMap) {
        // index --> header name
        String headerName = MapUtil.getStr(colNum2NameMap, colNum);
        // header name --> field name
        String fieldName = MapUtil.getStr(NAME_TO_FIELD, headerName);
        return fieldName;
    }

    /**
     * 填充合并空
     *
     * @param recLt
     */
    public static void fillBean(List<TableRec> recLt) {
        //
        String quarter = null, lessonNo = null, lessonName = null;
        String difficulty = null, f3 = null, importance = null;
        for (TableRec rec : recLt) {
            // 非空行
            if (StrUtil.isNotEmpty(rec.getQuarter())) {
                quarter = rec.getQuarter();
            }
            if (StrUtil.isNotEmpty(rec.getLessonNo())) {
                lessonNo = rec.getLessonNo();
            }
            if (StrUtil.isNotEmpty(rec.getLessonName())) {
                lessonName = rec.getLessonName();
            }
            if (StrUtil.isNotEmpty(rec.getDifficulty())) {
                difficulty = rec.getDifficulty();
            }
            if (StrUtil.isNotEmpty(rec.getF3())) {
                f3 = rec.getF3();
            }
            if (StrUtil.isNotEmpty(rec.getImportance())) {
                importance = rec.getImportance();
            }
            //
            rec.setQuarter(quarter);
            rec.setLessonNo(lessonNo);
            rec.setLessonName(lessonName);
            rec.setDifficulty(difficulty);
            rec.setF3(f3);
            rec.setImportance(importance);
        }
    }
}
